package com.oa.android.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.oa.android.R;


/**
 * Created by 邹啟华 on 2015/12/14.
 */
public class SearchActivity extends Activity implements View.OnClickListener {
    private EditText input;
    private TextView search;
    private LinearLayout close;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_activity);
        input = (EditText) findViewById(R.id.input);
        close = (LinearLayout) findViewById(R.id.close);
        search = (TextView) findViewById(R.id.search);
        close.setOnClickListener(this);
        search.setOnClickListener(this);
        input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                String searchStr = input.getText().toString().trim();
                if (actionId == EditorInfo.IME_ACTION_SEARCH
                        || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                    if (searchStr == null || "".equals(searchStr)) {
                        Toast.makeText(SearchActivity.this, "请输入单位关键字", Toast.LENGTH_SHORT).show();

                    } else {



                    }


                }

                return true;
            }
        });
    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.close:
                finish();
                break;

            case R.id.search:
                if (input.getText().toString().length() > 0) {
                    Intent intent = new Intent();
                    intent.putExtra("keyword", input.getText().toString());
                    setResult(RESULT_OK, intent);
                    finish();
                } else {
                    Toast.makeText(getApplicationContext(), "请输入你要查找内容！", Toast.LENGTH_SHORT).show();
                }


                break;

        }
    }
}
